/*
 * Session.java
 * 
 *  author: Daniel Rudigier
 *    date: 11.06.2008
 * 
 * 
 */
package ocumed.web.jsf.beans;

import ocumed.applikation.benutzerverwaltung.PatientLogin;
import ocumed.applikation.exceptions.LoginFailedException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * provides session functionality (managed bean)
 * 
 * @author Daniel Rudigier
 *
 */
public class WSession {
    private static final Log log = LogFactory.getLog(WSession.class);
    
    private String errormsg = "";    
    private PatientLogin loginCTRL;
    private Integer patientId;
    private Integer arztId;
    
    private String patient;
    private String arzt;
    private String username;
    private String password;
    
    private WScheduler scheduler;
        
    /**
     * try to login
     * @return status
     */
    public String login() {
        log.info("login called: " + username + ":" + password);
        try {
            loginCTRL = new PatientLogin(username, password);
            patientId = loginCTRL.getPatientId();
            arztId = loginCTRL.getArztId();
            patient = loginCTRL.getPatientName();
            arzt = loginCTRL.getArztName();
            
            scheduler.setSession(this);
            scheduler.refresh();
            
            return "success";
        } catch (LoginFailedException e) {
            return "failed";
        }
    }
    
    /**
     * @return scheduler
     */
    public WScheduler getScheduler() {
        return scheduler;
    }
    
    /**
     * @param scheduler to set
     */
    public void setScheduler(WScheduler scheduler) {
        this.scheduler = scheduler;
    }
    
    /**
     * @return patientId
     */
    public Integer getPatientId() {
        return patientId;
    }
    
    /**
     * @param patientId to set
     */
    public void setPatientId(Integer patientId) {
        this.patientId = patientId;
    }
    
    /**
     * @return arztId
     */
    public Integer getArztId() {
        return arztId;
    }
    
    /**
     * @param arztId to set
     */
    public void setArztId(Integer arztId) {
        this.arztId = arztId;
    }
    
    /**
     * @return name
     */
    public String getPatient() {
        return patient;
    }
    
    /**
     * @param name to set
     */
    public void setPatient(String name) {
        this.patient = name;
    }
    
    /**
     * @return arzt
     */
    public String getArzt() {
        return arzt;
    }
    
    /**
     * @param arzt to set
     */
    public void setArzt(String arzt) {
        this.arzt = arzt;
    }
    
    /**
     * try to logout
     */
    public void logout() {
        throw new UnsupportedOperationException();
    }
    
    /**
     * @return errormsg
     */
    public String getErrormsg() {
        return errormsg;
    }

    /**
     * @return username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    
}
